package com.baizhi.controller;

import com.baizhi.dto.PageDTO;
import com.baizhi.entity.Video;
import com.baizhi.service.VideoService;
import com.baizhi.vo.CommonVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.HashMap;

@CrossOrigin
@RestController
@RequestMapping("video")
public class VideoController {
    private static final Logger log = LoggerFactory.getLogger(VideoController.class);
    @Resource
    VideoService videoService;

    @RequestMapping("queryAllPage")
    public HashMap<String,Object> queryAllPage(@RequestBody PageDTO pageDTO){
        log.info("当前页:{}",pageDTO.getPage());
        log.info("每页的行数:{}",pageDTO.getPageSize());
        HashMap<String, Object> map = videoService.queryAllPage(pageDTO);
        return map;
    }
    @RequestMapping("update")
    public HashMap<String,Object> update(@RequestBody Video video){
        log.info("修改的对象:{}",video);
        HashMap<String, Object> map = videoService.update(video);
        return map;
    }
    @RequestMapping("queryById")
    public Video queryById(String id){
        log.info("传的id:{}",id);
        return videoService.queryById(id);
    }
    @RequestMapping("add")
    public HashMap<String,Object>add(@RequestBody Video video){
        log.info("添加的对象:{}",video);
        return videoService.add(video);
    }
    @ResponseBody
    @RequestMapping("delete")
    public CommonVO delete(@RequestBody Video video){
        log.info("删除的对象:{}",video);
        try {
            videoService.delete(video);
           return CommonVO.success("删除数据成功");
        } catch (Exception e) {
            e.printStackTrace();
           return CommonVO.success("删除失败");
        }
    }
    @ResponseBody
    @RequestMapping("uploadHeadImg")
    public HashMap<String, String> uploadHeadImg(MultipartFile videoFile){
        return videoService.uploadVideoALiY(videoFile);
    }
}
